package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.DMaterialModelItemDao;
import com.hongxun.modules.bss.entity.DMaterialModelItemEntity;
import com.hongxun.modules.bss.service.DMaterialModelItemService;


@Service("dMaterialModelItemService")
public class DMaterialModelItemServiceImpl implements DMaterialModelItemService {
    @Autowired
    private DMaterialModelItemDao dMaterialModelItemDao;

    @Override
    public DMaterialModelItemEntity queryObject(String guid) {
        return dMaterialModelItemDao.queryObject(guid);
    }

    @Override
    public List<DMaterialModelItemEntity> queryList(Map<String, Object> map) {
        return dMaterialModelItemDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return dMaterialModelItemDao.queryTotal(map);
    }

    @Override
    public void save(DMaterialModelItemEntity dMaterialModelItem) {
        if (dMaterialModelItem.getGuid() == null || dMaterialModelItem.getGuid().equals("")) {

            dMaterialModelItem.setGuid(UUID.randomUUID().toString());
        }
        dMaterialModelItemDao.save(dMaterialModelItem);
    }

    @Override
    public void update(DMaterialModelItemEntity dMaterialModelItem) {
        dMaterialModelItemDao.update(dMaterialModelItem);
    }

    @Override
    public void delete(String guid) {
        dMaterialModelItemDao.delete(guid);
    }

    @Override
    public void deleteBatch(String[] guids) {
        dMaterialModelItemDao.deleteBatch(guids);
    }

    @Override
    public void insertOrReplaceOrDelete(List<DMaterialModelItemEntity> entities) {
        for (DMaterialModelItemEntity d : entities) {
            if (d.getDatastate().equals("删除")) {
                dMaterialModelItemDao.delete(d.getGuid());
            } else {
                DMaterialModelItemEntity dMaterialCostEntity = dMaterialModelItemDao.queryObject(d.getGuid());
                if (dMaterialCostEntity == null) {
                    dMaterialModelItemDao.save(d);
                } else {
                    dMaterialModelItemDao.update(d);
                }
            }
        }
    }

}
